using System;
using Microsoft.SPOT;
using Toolbox.NETMF.Hardware;
using System.Text;
using System.IO.Ports;

namespace N2Plus_GPS
{
    /// <summary>
    /// Class that will give us extended functionality on some objects
    /// </summary>
    public static class Extensions
    {
        /// <summary>
        /// Writes a complete line on the LCD unit, clearing previous data
        /// </summary>
        /// <param name="pLCD">The actual LCD unit to be written on</param>
        /// <param name="pRow">The row onto the data should be written</param>
        /// <param name="pValue">The value to be written</param>
        public static void WriteLine(this Hd44780Lcd pLCD, byte pRow, String pValue)
        {
            if (pLCD != null)
            {
                string lvBlanks = string.Empty;
                for (int i = 0; i < pLCD.Columns; i++) lvBlanks += " ";
                pLCD.ChangePosition(pRow, 0);
                pLCD.Write(lvBlanks);

                pLCD.ChangePosition(pRow, 0);
                pLCD.Write(pValue);
            }
        }

        /// <summary>
        /// Converts a string to Byte array
        /// </summary>
        /// <param name="pString">The string to be converted</param>
        /// <returns>THe resultant byte array</returns>
        public static byte[] ToByteArray(this string pString)
        {
            return Encoding.UTF8.GetBytes(pString);
        }
    }
}
